package com.tanhua.controller;

import com.tanhua.service.SettingsService;
import model.vo.PageResult;
import model.vo.SettingsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo settingsVo = settingsService.settings();
        return ResponseEntity.ok(settingsVo);
    }

    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map) {
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        settingsService.saveSetting(map);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize
    ) {
        PageResult pageResult = settingsService.blackList(page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId) {
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }
}
